package com.tqjc.plccontrol.utils;

/**
 * @projectName: BaotouSteel
 * @className: PlcResult
 * @author: Patienyon
 * @description: TODO
 * @date: 2023/6/16 17:02
 */

import com.alibaba.fastjson.JSONObject;

/**
 * @Description: PLC操作返回类
 * @author: pzy
 * @date: 2022年08月03日 15:13
 */

public class PlcResult<T> {
    public T getData() {
        return data;
    }

    private boolean success;
    private String msg;
    private T data;


    /**
     * create by: pzy
     * description: 正确方法
     * create time: 2022/2/21 10:15
     *
     * @return com.tqjc.c19032.semiautomatic.SemiworkResult<T>
     * @param: [data]
     */
    public static PlcResult ok() {
        PlcResult res = new PlcResult();
        res.setSuccess(true);
        res.setMsg("操作成功");
        return res;
    }

    /**
     * create by: pzy
     * description: PLC操作成功返回
     * create time: 2022/8/3 15:16
     *
     * @return com.tqjc.business.plccontrol.PlcResult<T>
     * @param: [data]
     */
    public static <T> PlcResult<T> ok(T data) {
        PlcResult res = new PlcResult();
        res.setData(data);
        res.setSuccess(true);
        res.setMsg("操作成功");
        return res;
    }


    /**
     * create by: pzy
     * description: PLC操作错误返回
     * create time: 2022/8/3 15:15
     *
     * @return com.tqjc.business.plccontrol.PlcResult
     * @param: [msg]
     */
    public static PlcResult fail(String msg) {
        PlcResult res = new PlcResult();
        res.setSuccess(false);
        res.setMsg(msg);
        return res;
    }


    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }

}
